package com.kefu.common.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

//发布消息
public class PubClient {
    private static Logger logger = LoggerFactory.getLogger(PubClient.class);
    private static JedisPool jedisPool =JedisUtils.jedisPool;
    private static Jedis jedis = jedisPool.getResource();

    /**
     * 发布一个消息
     *
     * @param channel
     * @param message
     */
    public static void publishMsg(String channel, String message) {
        try {
            jedis.publish(channel, message);
            logger.info("publishMsg {} = {}", channel, message);
        } catch (Exception e) {
            logger.error("publishMsg {} = {}", channel, message, e);
        }
    }
    /**
     * 取消某个频道的订阅
     */
    public static void close(String channel){
        publishMsg(channel, "quit");
    }

}